feature/NestedBreakWithLabel #510
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Saelo,
First of all, I sincerely apologize for the long delay regarding the implementation of
LabelStatement
.Following your suggestion #479, I have split this feature into two separate PRs, LoopContinueNested and NestedBreak.
This PR specifically addresses the issue of NestedBreak. I have restructured the approach as follows:
Here is the ECMA definition of
LabelStatement
:And the full enumeration of
Statement
types:However, not all
Statement
types can meaningfully work with a label.Here is my analysis of statements that should not be considered:
Declaration Statements
Thus, all declaration-related statements can be ignored, as this is only a legacy behavior with no practical significance.
DebuggerStatement
This only exists in the trivial form of
label: debugger;
, which we can safely ignore.ExpressionStatement
Since a
LabelStatement
must be followed by a single validStatement
, ExpressionStatements are essentially limited to cases likelabel: break label;
, which are not meaningful for our purposes.ReturnStatement
Since
return
is only allowed inside function bodies, it cannot properly be labeled.After excluding the above, the remaining valid statements that can be used with a label are:
IfStatement
TryStatement
WithStatement
BlockStatement
SwitchStatement
DoWhileStatement
ForStatement
ForInStatement
ForOfStatement
WhileStatement
This matches the examples you previously mentioned.
Importantly, all valid label targets are recursive structures, which means that the existing
loopLabelStack
design can be reused.Here are some detailed points about the implementation:
Fuzzilli does not abstract basic grammar types like
Statement
andExpression
.Therefore, it is not possible to batch-handle statements generically.
Labeling cannot be universally applied to every JS context as you initially suggested.
A label must anchor the beginning of a code block; otherwise, a
break
would not know its valid break target.Fuzzilli’s context system is designed top-down.
Even though JavaScript has a unified
break;
statement, in Fuzzilli the context system usingisSubSet(of: originContext)
enforces the separation of different break types.Therefore, I chose to follow the existing architectural style: implement a dedicated
xxxNestedBreak
for each context, instead of creating a genericnestedBreak
.I have extended the context system by adding three missing contexts:
ifBlock
,tryBlock
, andcodeBlock
.Based on this, I have implemented six
NestedBreak
operations:switchNestedBreak
blockNestedBreak
ifNestedBreak
withNestedBreak
tryNestedBreak
loopNestedBreak
I also restructured the auxiliary stacks needed for these operations, ensuring that multiple labeled statements can coexist and be reused properly.
I sincerely appreciate your patience and understanding!